package com.matuw.android.adapter.listview;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;

import androidx.annotation.NonNull;

import com.matuw.android.adapter.ViewHolder;


/**
 * @author Shihwan
 * @date 2025/4/28
 */
public class QinViewHolder implements ViewHolder {

    private final SparseArray<View> cacheViews = new SparseArray<>();

    @NonNull
    private final View itemView;

    private int adapterPosition = NO_POSITION;

    public QinViewHolder(@NonNull View itemView) {
        this.itemView = itemView;
    }

    @NonNull
    @Override
    public View get() {
        return itemView;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <V extends View> V getView(int viewId) {
        View cacheView = cacheViews.get(viewId);
        if (cacheView == null) {
            V view = itemView.findViewById(viewId);
            cacheViews.put(viewId, view);
            return view;
        }

        return (V) cacheView;
    }

    @Override
    public int getAdapterPosition() {
        return adapterPosition;
    }

    public void setAdapterPosition(int adapterPosition) {
        this.adapterPosition = adapterPosition;
    }

    @NonNull
    @Override
    public Context getContext() {
        return itemView.getContext();
    }
}
